<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >

      <el-row>
        <el-form-item label="渠道客户" prop="orderType">
          <el-select
            v-model="queryParams.orderType"
            placeholder="请选择渠道客户"
            clearable
            class="!w-100px"
          >
            <el-option
              v-for="dict in getIntDictOptions(DICT_TYPE.DISPATCH_ORDER_TYPE)"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>

        </el-form-item>
        <el-form-item label="门店" prop="storeId">
          <el-select
            v-model="queryParams.storeId"
            placeholder="请选择门店"
            clearable
            filterable
            class="!w-150px"
          >
            <el-option
              v-for="dict in storeList"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="车牌" prop="licensePlate">
          <el-input
            v-model="queryParams.licensePlate"
            placeholder="请输入车牌"
            clearable
            @keyup.enter="handleQuery"
            class="!w-100px"
          />
        </el-form-item>
        <!--        <el-form-item label="联系电话" prop="telephone">-->
        <!--          <el-input-->
        <!--            v-model="queryParams.telephone"-->
        <!--            placeholder="请输入联系电话"-->
        <!--            clearable-->
        <!--            @keyup.enter="handleQuery"-->
        <!--            class="!w-240px"-->
        <!--          />-->
        <!--        </el-form-item>-->
        <el-form-item>
          <el-button @click="handleQuery">
            <Icon icon="ep:search" class="mr-5px"/>
            搜索
          </el-button>
          <el-button @click="resetQuery">
            <Icon icon="ep:refresh" class="mr-5px"/>
            重置
          </el-button>
        </el-form-item>
        <el-form-item>

          <el-button
            type="primary"
            plain
            @click="openForm('create')"
            v-hasPermi="['dispatch:order:create']"
            size="small"
          >
            <Icon icon="ep:plus" class="mr-5px"/>
            新增
          </el-button>
          <el-button
            type="success"
            plain
            @click="handleExport"
            :loading="exportLoading"
            v-hasPermi="['dispatch:order:export']"
            size="small"
          >
            <Icon icon="ep:download" class="mr-5px"/>
            导出
          </el-button>
        </el-form-item>
      </el-row>


    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" border :data="list" :stripe="true"
              :summary-method="getSummaries" show-summary :show-overflow-tooltip="true">


      <el-table-column fixed="left" label="操作" min-width="60" align="center">
        <template #default="scope">
          <el-popover style="position: relative" :visible="popoverVisible == scope.row.id"
                      placement="bottom-start"
                      :width="60">

            <el-row class="mb-8px">
              <el-col :span="24">
                <el-button
                  link
                  type="primary"
                  @click="openForm('update', scope.row.id)"
                  v-hasPermi="['dispatch:order:update']"
                >
                  编辑
                </el-button>
              </el-col>
            </el-row>


            <el-row class="mb-8px">
              <el-col :span="24">
                <el-button
                  link
                  type="primary"
                  @click="handleDispatch(scope.row)"
                  v-hasPermi="['dispatch:order:update']"
                >
                  指派
                </el-button>
              </el-col>
            </el-row>


            <el-row class="mb-8px">
              <el-col :span="24">
                <el-button
                  link
                  type="danger"
                  @click="handleDelete(scope.row.id)"
                  v-hasPermi="['dispatch:order:delete']"
                >
                  删除
                </el-button>
              </el-col>
            </el-row>


            <el-row class="mb-8px">
              <el-col :span="24">
                <el-button
                  link
                  type="primary"
                  @click="handlePic(scope.row)"
                >
                  上传图片
                </el-button>
              </el-col>
            </el-row>
            <div class="popoverCloseBtn" @click="closePopover()">关闭</div>
            <!--            <img style="text-align: right;width: 32px;" src="@/assets/imgs/close.png" @click="closePopover()"/>-->
            <template #reference>
              <img src="@/assets/imgs/more_edit.png" class="linkBtn" @click="openForm('update', scope.row.id)" @contextmenu.prevent="handleRightClick(scope.row.id)"
                   />
            </template>
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column
        label="日期"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        fixed="left"
        width="120px"
      />


      <!--      <el-table-column label="编号" align="center" prop="id"/>-->
      <el-table-column label="门店" fixed="left" min-width="140" prop="storeId">
        <!--        <template #default="scope">-->
        <!--          <el-tag type="primary">{{ getStoreName(scope.row) }}</el-tag>-->
        <!--        </template>-->
        <template #default="scope">
          <el-tag class="storeTag" v-if="scope.row.storeName =='待派'" type="warning" @click="handleDispatch(scope.row)">{{ scope.row.storeName }}</el-tag>
          <el-tag class="storeTag"  v-else type="primary" @click="handleDispatch(scope.row)">{{ scope.row.storeName }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="渠道客户" fixed="left" align="center" min-width="100"
                       prop="orderType">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.DISPATCH_ORDER_TYPE" :value="scope.row.orderType"/>
        </template>
      </el-table-column>

      <el-table-column label="车型/服务" fixed="left" min-width="200" prop="carType"/>

      <el-table-column label="产品名称" fixed="left" min-width="200" prop="productName"/>


      <el-table-column label="车牌" fixed="left" min-width="100" prop="licensePlate"/>
      <el-table-column label="订单价格" align="center" min-width="130" prop="orderPrice"/>
      <el-table-column label="参考订单价" prop="historyPrice" width="100">
        <template #default="scope">
          <el-button
            link
            v-for="(value, index) in scope.row.orderPriceList" :key="index"
            type="primary"
            @click="openHistoryPriceDetail(scope.row,'channel')"
          >
            <el-tag type="success">
              {{ value }}
            </el-tag>
            <!--          </el-button>-->
            <!--            <el-tag v-if="scope.row.historyOrderPrice != null && scope.row.historyOrderPrice.length > 0" type="success">{{-->
            <!--                scope.row.historyOrderPrice-->
            <!--              }}-->
            <!--            </el-tag>-->
          </el-button>
        </template>
      </el-table-column>

      <el-table-column label="派单价格" align="center" min-width="130" prop="dispatchPrice"/>

      <el-table-column label="参考派单价" prop="historyPrice" width="100">
        <template #default="scope">
          <el-button
            link
            v-for="(value, index) in scope.row.dispatchPriceList" :key="index"
            type="primary"
            @click="openHistoryPriceDetail(scope.row,'dispatch')"
          >
            <el-tag type="success">
              {{ value }}
            </el-tag>
            <!--            <el-tag v-if="scope.row.historyDispatchPrice != null && scope.row.historyDispatchPrice.length > 0" type="success">{{-->
            <!--                scope.row.historyDispatchPrice-->
            <!--              }}-->
            <!--            </el-tag>-->
          </el-button>
        </template>
      </el-table-column>

      <el-table-column label="联系电话" align="center" min-width="120" prop="telephone"/>


      <!--      <el-table-column label="排序" align="center" prop="sort" />-->
      <el-table-column label="车主地址" min-width="220" prop="customerAddrress"/>

      <el-table-column label="VIN" align="center" min-width="180" prop="vin"/>

      <el-table-column label="图片信息" :min-width="200" align="center" prop="imgUrl">
        <template #default="scope">
          <el-image
            style="width: 20px; height: 20px"
            :src="img"
            v-for="(img,index) in scope.row.imgUrl"
            :key="index"
            z-index="1000"
            :initial-index="index"
            hide-on-click-modal
            preview-teleported
            :preview-src-list="scope.row.imgUrl"
          />
        </template>
      </el-table-column>

      <el-table-column
        label="图片上传日期"
        align="center"
        prop="imgDate"
        :formatter="dateFormatter"
        width="160px"
      />
      <el-table-column label="单号" align="center" min-width="200" prop="no"/>
      <el-table-column label="品牌" align="center" min-width="80" prop="brandId">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ERP_GLASS_BRAND" :value="scope.row.brandId"/>
        </template>
      </el-table-column>
      <el-table-column label="业务类型" align="center" min-width="100" prop="saleType">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ERP_SALE_TYPE" :value="scope.row.saleType"/>
        </template>
      </el-table-column>
      <!--      <el-table-column label="车型" align="center" min-width="200" prop="carType"/>-->
      <el-table-column label="车主" align="center" min-width="100" prop="customerName"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="创建者" align="center" prop="creator"/>

      <el-table-column label="开启状态" align="center" min-width="120" prop="status">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <!--      <el-table-column class="btn-wap" label="操作" min-width="200" align="center" fixed="right">-->
      <!--        <template #default="scope">-->

      <!--          <el-button-->
      <!--            link-->
      <!--            type="primary"-->
      <!--            @click="handlePic(scope.row)"-->
      <!--          >-->
      <!--            上传图片-->
      <!--          </el-button>-->

      <!--          <el-button-->
      <!--            link-->
      <!--            type="primary"-->
      <!--            @click="openForm('update', scope.row.id)"-->
      <!--            v-hasPermi="['dispatch:order:update']"-->
      <!--          >-->
      <!--            编辑-->
      <!--          </el-button>-->

      <!--          <el-button-->
      <!--            link-->
      <!--            type="primary"-->
      <!--            @click="handleDispatch(scope.row)"-->
      <!--            v-hasPermi="['dispatch:order:update']"-->
      <!--          >-->
      <!--            指派-->
      <!--          </el-button>-->

      <!--          <el-button-->
      <!--            link-->
      <!--            type="danger"-->
      <!--            @click="handleDelete(scope.row.id)"-->
      <!--            v-hasPermi="['dispatch:order:delete']"-->
      <!--          >-->
      <!--            删除-->
      <!--          </el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>


  <Dialog title="指派门店" v-model="dispatchDialogVisible" width="40%">
    <el-form v-loading="formLoading">
      <el-form-item label="派单类型" label-width="80px">
        <el-radio-group v-model="storeRadio">
          <el-radio
            v-for="dict in getIntDictOptions(DICT_TYPE.DISPATCH_TYPE)"
            :key="dict.value"
            :label="dict.value"
          >
            {{ dict.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item v-if="storeRadio === 1" label="门店" label-width="80px">

        <el-select
          v-model="dispatchData.storeId"
          placeholder="请选择门店"
          filterable
          clearable
          class="!w-230px"
        >
          <el-option
            v-for="dict in storeList"
            :key="dict.id"
            :label="dict.name"
            :value="dict.id"
          />
        </el-select>
        <el-button style="margin-left: 10px" @click="openAddStore" type="primary">新增</el-button>

      </el-form-item>


    </el-form>
    <template #footer>
      <el-button @click="submitDispatch" type="primary" :disabled="formLoading">确 定</el-button>
      <el-button @click="dispatchDialogVisible = false">取 消</el-button>
      <el-button type="danger" @click="cancelDispatch">撤销指派</el-button>
    </template>

  </Dialog>


  <Dialog title="上传图片" v-model="picDialogVisible" width="50%">
    <el-form v-loading="formLoading">
      <el-form-item label="图片信息" label-width="80px">
        <UploadImgs v-model="picData.imgUrl"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="submitPic" type="primary" :disabled="formLoading">确 定</el-button>
      <el-button @click="picDialogVisible = false">取 消</el-button>
    </template>

  </Dialog>

  <!--  历史价格详情-->
  <el-dialog
    v-model="historyPriceDetailVisible"
    title="参考派单报价"
    width="40%"
  >
    <!--    <div style="text-align: center;margin-bottom: 20px">{{historyPriceProductName}}</div>-->
    <!--    <el-tag class="mr-3" type="success">最低报价{{historyPriceDetail.minDispatchPrice}}</el-tag>-->
    <!--    <el-tag class="mr-3" type="danger">最高报价{{historyPriceDetail.maxDispatchPrice}}</el-tag>-->
    <el-tag class="mr-3" v-for="(value, key, index) in historyPriceDetail.mapDispatchPrice"
            :key="index">【{{ key }}】{{ value }}
    </el-tag>
    <el-table v-loading="historyPriceLoading" :data="historyPriceDetail.list" border :stripe="true"
              :show-overflow-tooltip="true">
      <el-table-column label="门店" align="center" prop="storeName"/>
      <el-table-column label="品牌" align="center" prop="brandName"/>
      <el-table-column label="时间" align="center" prop="createTime" :formatter="dateFormatter2"/>
      <el-table-column label="派单价格" align="center" prop="dispatchPrice"/>
    </el-table>

  </el-dialog>


  <el-dialog
    v-model="historyChannelPriceDetailVisible"
    title="参考订单价格"
    width="40%"
  >
    <!--    <div style="text-align: center;margin-bottom: 20px">{{historyPriceProductName}}</div>-->
    <!--    <el-tag class="mr-3" type="success">最低报价{{historyPriceDetail.minOrderPrice}}</el-tag>-->
    <!--    <el-tag class="mr-3" type="danger">最高报价{{historyPriceDetail.maxOrderPrice}}</el-tag>-->
    <el-tag class="mr-3" v-for="(value, key, index) in historyPriceDetail.mapPrice" :key="index">
      【{{ key }}】{{ value }}
    </el-tag>
    <el-table v-loading="historyPriceLoading" :data="historyPriceDetail.list" border :stripe="true"
              :show-overflow-tooltip="true">
      <el-table-column label="渠道" align="center" prop="orderType">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.DISPATCH_ORDER_TYPE" :value="scope.row.orderType"/>
        </template>
      </el-table-column>
      <el-table-column label="门店" align="center" prop="storeName"/>
      <el-table-column label="品牌" align="center" prop="brandName"/>
      <el-table-column label="时间" align="center" prop="createTime" :formatter="dateFormatter2"/>
      <el-table-column label="渠道价格" align="center" prop="orderPrice"/>
    </el-table>

  </el-dialog>


  <!-- 表单弹窗：添加/修改 -->
  <OrderForm ref="formRef" @success="getList"/>
</template>

<script setup lang="ts">
import {getIntDictOptions, getStrDictOptions, DICT_TYPE} from '@/utils/dict'
import {dateFormatter, dateFormatter2} from '@/utils/formatTime'
import download from '@/utils/download'
import {OrderApi, OrderVO} from '@/api/dispatch/order'
import {StoreApi, StoreVO} from '@/api/dispatch/store'
import OrderForm from './OrderForm.vue'
import ContentWrap from "@/components/ContentWrap/src/ContentWrap.vue";
import {ProductCategoryApi, ProductCategoryVO} from "@/api/erp/product/category";
import {defaultProps, handleTree} from "@/utils/tree";
import {ProductBrandApi, ProductBrandVO} from "@/api/erp/product/brand";
import {InquiryOrderApi} from "@/api/erp/inquiryorder";
import {string} from "vue-types";
import {erpCountInputFormatter, erpPriceInputFormatter, getSumValue} from "@/utils";
import {ElLoading} from "element-plus";

const historyPriceLoading = ref(true) // 列表的加载中
const historyPriceDetailVisible = ref(false) // 历史价格详情
const historyChannelPriceDetailVisible = ref(false) // 历史价格详情
const historyPriceList = ref([]) // 历史价格详情
const historyPriceProductName = ref()

const popoverVisible = ref(null);

const historyPriceDetail = reactive({
  list: [],
  mapPrice: undefined,
  mapDispatchPrice: undefined,
  minDispatchPrice: 0,
  maxDispatchPrice: 0,
  minOrderPrice: 0,
  maxOrderPrice: 0
})


const categoryList = ref<ProductCategoryVO[]>([]) // 产品分类列表
const brandList = ref<ProductBrandVO[]>([]) // 产品分类列表
/** 派单系统 订单 列表 */
defineOptions({name: 'Order'})
const message = useMessage() // 消息弹窗
const {t} = useI18n() // 国际化
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const loading = ref(true) // 列表的加载中
const dispatchDialogVisible = ref(false)
const picDialogVisible = ref(false)
const list = ref<OrderVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  orderType: undefined,
  storeId: undefined,
  licensePlate: undefined,
  telephone: undefined,
  customerName: undefined,
})

const storeRadio = ref(1);


const getSummaries = (param) => {

  const {columns, data} = param
  const sums: string[] = []
  columns.forEach((column, index: number) => {
    // if (index === 0) {
    //   sums[index] = '合计'
    //   return
    // }
    if (['orderPrice'].includes(column.property)) {
      // const sum = getSumValue(data.map((item) => Number(item[column.property])))
      // sums[index] = column.property === 'orderPrice' ? erpCountInputFormatter(sum) : erpPriceInputFormatter(sum)
      sums[index] = '' + erpPriceInputFormatter(sumOrderPrice.value);
    } else  if(['dispatchPrice'].includes(column.property)) {
      sums[index] = '' + erpPriceInputFormatter(sumDispatchPrice.value);
    } else {
      sums[index] = ''
    }
  })

  return sums
}

const handleDoubleClick = (id)=>{

}


const objectSpanMethod = (row, rowIndex) => {
  // if (rowIndex === 1) {
  //   // 如果是最后一行，则合并所有列
  //   return { rowspan: 1, colspan: 3 }; // 假设有三列
  // }
  // return { rowspan: 1, colspan: 1 };
}

/**
 * 处理店铺名称
 * @param id
 */
const getStoreName = (row) => {

  if (row.dispatchType === 2) {
    return '自营门店'
  }

  const store = storeList.value.find(item => item.id === row.storeId);
  if (store == null) {
    return '待派';
  }
  let belongProvince = store.belongProvince != null ? store.belongProvince + ' ' : '';
  let belongCity = store.belongCity != null ? store.belongCity + ' ' : '';
  let belongDistrict = store.belongDistrict != null ? store.belongDistrict + ' ' : '';
  return belongProvince + belongCity + belongDistrict + store.name;
}


const openPopoverVisible = async (id) => {
  // if (popoverVisible.value == null) {
  popoverVisible.value = id;
  // } else {
  //   popoverVisible.value = null;
  // }
}

const closePopover = async () => {
  popoverVisible.value = null;
}
const handleRightClick = (id) => {
  popoverVisible.value = id;
};


//查看价格详情
const openHistoryPriceDetail = async (row, type: string) => {

  historyPriceProductName.value = row.productName;
  let productId = row.productId;
  if (type === 'channel') {
    historyChannelPriceDetailVisible.value = true;
  } else {
    historyPriceDetailVisible.value = true;
  }
  historyPriceLoading.value = true;
  historyPriceList.value = [];

  // let r = await InquiryOrderApi.historyPriceDetail(productId)
  let r = await OrderApi.selectHistoryPriceRecord(productId);


  historyPriceDetail.list = r.list;

  historyPriceDetail.mapPrice = r.mapPrice;
  historyPriceDetail.mapDispatchPrice = r.mapDispatchPrice;

  // historyPriceDetail.minDispatchPrice = r.minDispatchPrice;
  // historyPriceDetail.maxDispatchPrice = r.maxDispatchPrice;
  // historyPriceDetail.minOrderPrice = r.minOrderPrice;
  // historyPriceDetail.maxOrderPrice = r.maxOrderPrice;

  historyPriceLoading.value = false;
}

/**
 * 派单相关数据
 */
const dispatchData = reactive({
  id: undefined,
  orderType: 2,
  saleTypeName: undefined,
  dispatchType: undefined,//派单类型
  storeId: undefined
})

/**
 * 照片信息
 */
const picData = reactive({
  id: undefined,
  imgUrl: []
})

const storeList = ref<StoreVO[]>([])
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中
const dialogVisible = ref(false);

const sumDispatchPrice = ref(0);
const sumOrderPrice = ref(0);
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await OrderApi.getOrderPage(queryParams)

    let page = data.page;
    list.value = page.list;
    total.value = page.total;

    let statistics = data.statistics;
    sumDispatchPrice.value = statistics.sumDispatchPrice;
    sumOrderPrice.value = statistics.sumOrderPrice;

  } finally {
    loading.value = false
  }
}


const handlePic = async (row) => {
  picDialogVisible.value = true;
  picData.id = row.id;
  picData.imgUrl = row.imgUrl;
}

const handleDispatch = async (row) => {
  dispatchDialogVisible.value = true;
  storeRadio.value = 1;

  dispatchData.brandId = 1;
  dispatchData.saleType = 1;
  dispatchData.id = row.id;
  dispatchData.storeId = undefined;

  dispatchData.channelName = undefined;

  let channelTypes = getIntDictOptions(DICT_TYPE.DISPATCH_ORDER_TYPE);
  channelTypes.forEach(item => {
    if (item.value === row.orderType) {
      dispatchData.channelName = item.label;
    }
  })

}

//撤销指派
const cancelDispatch = async () => {

  //确认是否需要撤销
  if (!await message.confirm("确定撤销吗？")) {
    return;
  }

  formLoading.value = true;
  try {
    await OrderApi.cancelDispatch(dispatchData.id);
    message.success(t("处理成功"))
    await getList()
    dispatchDialogVisible.value = false;
  } catch {
  } finally {
    formLoading.value = false;
  }
}

/**
 * 提交派单
 */
const submitDispatch = async () => {
  formLoading.value = true;
  try {
    if (storeRadio.value === 1 && dispatchData.storeId === undefined) {
      message.error("请选择门店");
      return;
    }
    dispatchData.dispatchType = storeRadio.value;//派单类型

    let types = getIntDictOptions(DICT_TYPE.ERP_SALE_TYPE);
    //匹配saleType 获取名称
    types.forEach(item => {
      if (item.value === dispatchData.saleType) {
        dispatchData.saleTypeName = item.label;
      }
    })


    await OrderApi.handleDispatch(dispatchData);
    message.success(t("处理成功"))
    await getList()
    dispatchDialogVisible.value = false;
  } catch {
  } finally {
    formLoading.value = false;
  }
}
const {push} = useRouter();

//快捷添加门店
function openAddStore() {
  push({path: "/dispatch/store", query: {doType: "handAdd"}});
}

/**
 * 提交图片信息
 */
const submitPic = async () => {
  formLoading.value = true;
  try {
    await OrderApi.handlePic(picData);
    message.success(t("处理成功"))
    await getList()
    picDialogVisible.value = false;
  } catch {
  } finally {
    formLoading.value = false;
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {

  //加载中
  const loading = ElLoading.service({
    lock: true,
    text: '查询中...',
    background: 'rgba(0, 0, 0, 0.7)',
  })
  try {
    popoverVisible.value = null;
    formRef.value.open(type, id)
  }finally {
    loading.close();
  }

}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    await message.delConfirm()
    await OrderApi.deleteOrder(id)
    message.success(t('处理成功'))
    await getList()
  } catch {
  }
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    await message.exportConfirm()
    exportLoading.value = true
    const data = await OrderApi.exportOrder(queryParams)
    download.excel(data, '派单系统 订单.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(async () => {

  // 产品分类
  let categoryData = await ProductCategoryApi.getProductCategorySimpleList()
  categoryList.value = handleTree(categoryData, 'id', 'parentId')

  // 加载品牌列表
  let brandData = await ProductBrandApi.getProductBrandSimpleList()
  brandList.value = handleTree(brandData, 'id', 'parentId')

  storeList.value = await StoreApi.getStoreSimpleList();
  getList()
})
onActivated(async () => {
  popoverVisible.value = null;

  storeList.value = await StoreApi.getStoreSimpleList();
  getList()
})

</script>

<style lang="scss" scoped>
:deep(.is-link) {
  margin: 0;
}
.storeTag{
  cursor: pointer;
}
</style>

